/**
 * Created by xnr on 19/12/30.
 */


import OSS from 'ali-oss'
import { format } from './tool.js'

const client = new OSS({
    region: 'oss-cn-hangzhou.aliyuncs.com',
    endpoint: 'oss-cn-hangzhou.aliyuncs.com',
    accessKeyId: 'LTAIr0JgJBRz9zSM',
    accessKeySecret: 'OdlElhCPhd0FLKbjPmB0d3vltN9pLh',
    bucket: 'weilai9-yufei',
});

function OSSUploader(files, cb) {
    for (let i = 0; i < files.length; i++) {
        var time = new Date()
        var time_ = format.Date(time)
        var fjname = files[i].name
        let name = "wlj/" + time_ + '/' + time.getTime() + '/' + fjname;
        const file = files[i]
        client.put(name, file).then((res) => {
            console.log(res);
            cb && cb(res)
        }).catch((err) => {
            console.log(err)
            cb && cb(false)
        })
    }
}

export default OSSUploader